package com.tedu.day07springmvc.controller;


import com.tedu.day07springmvc.pojo.dto.BmiDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BmiController {


    @RequestMapping("/bmi")
    @ResponseBody
    public String bmi(BmiDTO bmiDTO){
        //判断输入的值是否合法
        if(bmiDTO.getHeight()<0 || bmiDTO.getWeight()<0){
            return "输入不合法";
        }else if(bmiDTO.getHeight()>2.5 || bmiDTO.getWeight()>200){
            return "输入不合法";
        }else {
            //计算bmi = 体重/身高^2
            double bmi = bmiDTO.getWeight()/(bmiDTO.getHeight()*bmiDTO.getHeight());
            if(bmi<18.5){
                return "偏瘦";
            }else if(bmi<24){
                return "正常";
            }else if(bmi<27){
                return "微胖";
            }else {
                return "家庭过于幸福美满，建议减肥！";
            }
        }
    }
}
